<?php
/**
 * Copyright (C) 2010-2013 Oscar Valenzuela B. (ovalenzuela@xpertians.com)
 * 
 * This file is part of WarpIT.
 * WarpIT is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * WarpIT is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with WarpIT.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * This class cointains HSS Parsing methods for WarpIT
 * @author Oscar Valenzuela <ovalenzuela@xpertians.com>
 * @version 1.0
 * @package WarpIT!
 * @copyright Copyright (C) 2010-2013 Xpertians SpA
 * @license GNU GPLv3 or later
 * @link http://www.xpertians.com
 */
 
Class Parse_HSS{
	/**
	 * XML to parse
	 *
	 * @var string
	 */
	private $xml;
	
	/**
	 * Array to return
	 *
	 * @var mixed
	 */
	private $res;
	
	/**
	 * Parse_HSS is the constructor of this class
	 *
	 */
	function Parse_HSS(){
		$this->res	= array();
	}
	
	/**
	 * Parse_SUB XML to Array for HSS SUB responses
	 *
	 * Following syntax are recognized :
	 *
	 * @param string $xml Original XML
	 * @return array
	 */
	function Parse_SUB($xml){
		$doc 			= new DOMDocument();
		$doc->loadXML($xml);
		$res			= array();
		$res['ResultCode']	= $doc->getElementsByTagName( "ResultCode" )->item(0)->nodeValue;
		$res['ResultDesc']	= $doc->getElementsByTagName( "ResultDesc" )->item(0)->nodeValue;
		$res['HLRSN']		= $doc->getElementsByTagName( "HLRSN" )->item(0)->nodeValue;
		$res['IMSI']		= $doc->getElementsByTagName( "IMSI" )->item(0)->nodeValue;
		$res['ISDN']		= $doc->getElementsByTagName( "ISDN" )->item(0)->nodeValue;
		$res['CardType']	= $doc->getElementsByTagName( "CardType" )->item(0)->nodeValue;
		$res['NAM']		= $doc->getElementsByTagName( "NAM" )->item(0)->nodeValue;
		$res['CATEGORY']	= $doc->getElementsByTagName( "CATEGORY" )->item(0)->nodeValue;
		$res['OCSI_ID']         = $doc->getElementsByTagName( "OCSI_ID" )->item(0)->nodeValue;		

		$i			= 0;
		foreach($doc->getElementsByTagName( "TS" ) AS $ts){
			$res['BASIC_SERVICE']['TS'][$i]		= $ts->nodeValue;
			$i++;
		}
		$i			= 0;
		foreach($doc->getElementsByTagName( "BS" ) AS $bs){
			$res['BASIC_SERVICE']['BS'][$i]		= $bs->nodeValue;
			$i++;
		}
		$res['DEFAULTCALL_TS']	= $doc->getElementsByTagName( "DEFAULTCALL_TS" )->item(0)->nodeValue;
		$res['ODBENTE']		= $doc->getElementsByTagName( "ODBENTE" )->item(0)->nodeValue;
		$res['CFNRY']		= $doc->getElementsByTagName( "CFNRY" )->item(0)->nodeValue;
		$res['CFNRY_FTN']	= $doc->getElementsByTagName( "CFNRY_FTN" )->item(0)->nodeValue;
		$res['CFNRC']		= $doc->getElementsByTagName( "CFNRC" )->item(0)->nodeValue;
		$res['CFNRC_FTN']	= $doc->getElementsByTagName( "CFNRC_FTN" )->item(0)->nodeValue;
		$res['ODBPB3']		= $doc->getElementsByTagName( "ODBPB3" )->item(0)->nodeValue;
		$res['ODBOC']		= $doc->getElementsByTagName( "ODBOC" )->item(0)->nodeValue;
		$res['ODBIC']		= $doc->getElementsByTagName( "ODBIC" )->item(0)->nodeValue;
		$res['BAOC']		= $doc->getElementsByTagName( "BAOC" )->item(0)->nodeValue;
		$res['BOIC']		= $doc->getElementsByTagName( "BOIC" )->item(0)->nodeValue;
		$res['BOICEXHC']	= $doc->getElementsByTagName( "BOICEXHC" )->item(0)->nodeValue;
		$res['BAIC']		= $doc->getElementsByTagName( "BAIC" )->item(0)->nodeValue;
		$res['BICROAM']		= $doc->getElementsByTagName( "BICROAM" )->item(0)->nodeValue;
		$res['CLIP']		= $doc->getElementsByTagName( "CLIP" )->item(0)->nodeValue;
		$res['CLIR']		= $doc->getElementsByTagName( "CLIR" )->item(0)->nodeValue;
		$res['CW']		= $doc->getElementsByTagName( "CW" )->item(0)->nodeValue;
		$res['HOLD']		= $doc->getElementsByTagName( "HOLD" )->item(0)->nodeValue;
		$res['MPTY']		= $doc->getElementsByTagName( "MPTY" )->item(0)->nodeValue;
		$res['ODBROAM']		= $doc->getElementsByTagName( "ODBROAM" )->item(0)->nodeValue;
		$res['BACKTONE']	= $doc->getElementsByTagName( "plmn-specificSS-8" )->item(0)->nodeValue;
		
		$res['SMDP']		= $doc->getElementsByTagName( "SMDP" )->item(0)->nodeValue;
		$res['RROption']	= $doc->getElementsByTagName( "RROption" )->item(0)->nodeValue;
		$res['CFU']		= $doc->getElementsByTagName( "CFU" )->item(0)->nodeValue;
		$res['CFB']		= $doc->getElementsByTagName( "CFB" )->item(0)->nodeValue;
		return $res;
	}
	
	/**
	 * Parse_DYNSUB XML to Array for HSS DYNSUB responses
	 *
	 * Following syntax are recognized :
	 *
	 * @param string $xml Original XML
	 * @return array
	 */
	function Parse_DYNSUB($xml){
		$doc 			= new DOMDocument();
		$doc->loadXML($xml);
		$res			= array();
		$res['SC']		= $doc->getElementsByTagName( "SC" )->item(0)->nodeValue;
		$res['MMEHOST']		= $doc->getElementsByTagName( "MMEHOST" )->item(0)->nodeValue;
		$res['VLRNUM']		= $doc->getElementsByTagName( "VlrNum" )->item(0)->nodeValue;
		$res['MSCNUM']		= $doc->getElementsByTagName( "MscNum" )->item(0)->nodeValue;
		$res['SGSNNUM']		= $doc->getElementsByTagName( "SgsnNum" )->item(0)->nodeValue;
		if(trim($res['MSCNUM'])!=""){
			include("Request_HEL.php");
			$operatorArr	= getOperatorInfo($res['MSCNUM']);
			$res['COUNTRY']		= $operatorArr['country'];
			$res['OPERATOR']	= $operatorArr['operator'];
			$res['CENTRAL']		= $operatorArr['central'];
		}
		return $res;
	}
	
	/**
	 * Parse_CFALL XML to Array for HSS CFALL responses
	 *
	 * Following syntax are recognized :
	 *
	 * @param string $xml Original XML
	 * @return array
	 */
	function Parse_CFALL($xml){
		$doc 			= new DOMDocument();
		$doc->loadXML($xml);
		$res			= array();
		$res['CFU_FTN']		= $doc->getElementsByTagName( "CFU_FTN" )->item(0)->nodeValue;
		$res['CFU_FTN']		= preg_replace("/[^A-Za-z0-9 ]/", '', $res['CFU_FTN']);
		$res['CFU_FTN']		= str_replace("NULL","",$res['CFU_FTN']);
		$res['CFB_FTN']		= $doc->getElementsByTagName( "CFB_FTN" )->item(0)->nodeValue;
		$res['CFB_FTN']		= preg_replace("/[^A-Za-z0-9 ]/", '', $res['CFB_FTN']);
		$res['CFB_FTN']		= str_replace("NULL","",$res['CFB_FTN']);
		return $res;
	}
	
	/**
	 * Parse_ECATEGORY XML to Array for HSS ECATEGORY responses
	 *
	 * Following syntax are recognized :
	 *
	 * @param string $xml Original XML
	 * @return array
	 */
	function Parse_ECATEGORY($xml){
		$doc 			= new DOMDocument();
		$doc->loadXML($xml);
		$res			= array();
		$res['ECATEGORY']	= $doc->getElementsByTagName( "ECATEGORY" )->item(0)->nodeValue;
		return $res;
	}
	
	/**
	 * Parse_CWAIT XML to Array for HSS CWAIT responses
	 *
	 * Following syntax are recognized :
	 *
	 * @param string $xml Original XML
	 * @return array
	 */
	function Parse_CWAIT($xml){
		$doc 			= new DOMDocument();
		$doc->loadXML($xml);
		$res			= array();
		$res['CWAIT']		= $doc->getElementsByTagName( "CWAIT" )->item(0)->nodeValue;
		return $res;
	}
	
	/**
	 * Parse_OPTGPRS XML to Array for HSS OPTGPRS responses
	 *
	 * Following syntax are recognized :
	 *
	 * @param string $xml Original XML
	 * @return array
	 */
	function Parse_OPTGPRS($xml){
		$doc 			= new DOMDocument();
		$doc->loadXML($xml);
		$res			= array();
		
		$i			= 0;
		foreach($doc->getElementsByTagName( "CNTXID" ) AS $CNTXID){
			$res['GPRS_DATA']['CNTXID'][$i]		= $CNTXID->nodeValue;
			$i++;
		}
		
		$i			= 0;
		foreach($doc->getElementsByTagName( "APNTPLID" ) AS $APNTPLID){
			$res['GPRS_DATA']['APNTPLID'][$i]	= $APNTPLID->nodeValue;
			$i++;
		}
		
		$i			= 0;
		foreach($doc->getElementsByTagName( "QOSTPLID" ) AS $QOSTPLID){
			$res['GPRS_DATA']['QOSTPLID'][$i]	= $QOSTPLID->nodeValue;
			$i++;
		}
		
		$i			= 0;
		foreach($doc->getElementsByTagName( "EPS_QOSTPLID" ) AS $EPS_QOSTPLID){
			$res['GPRS_DATA']['EPS_QOSTPLID'][$i]	= $EPS_QOSTPLID->nodeValue;
			$i++;
		}
		
		$i			= 0;
		foreach($doc->getElementsByTagName( "PDPTYPE" ) AS $PDPTYPE){
			$res['GPRS_DATA']['PDPTYPE'][$i]	= $PDPTYPE->nodeValue;
			$i++;
		}
		
		return $res;
	}
}

?>
